package network.course3.fixedthreadpool;

public class Person implements Runnable {
    private String name;
    private double outmoney;
    private String type;
    private Account account;

    public Person(String name, double outmoney, String type, Account account) {
        this.name = name;
        this.outmoney = outmoney;
        this.type = type;
        this.account = account;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Account getAccount() {
        return account;
    }

    public void setAccount(Account account) {
        this.account = account;
    }

    public double getOutmoney() {
        return outmoney;
    }

    public void setOutmoney(double outmoney) {
        this.outmoney = outmoney;
    }

    @Override
    public void run() {
        while (account.getMoney() >= outmoney) {
            synchronized (account) {
                double result = account.outMoney(outmoney, type);
                System.out.println(type + "取钱" + outmoney + "剩余" + result + "元！");
            }
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}